#include "Text.h"

namespace BottomLayer
{
	extern LPDIRECT3DDEVICE9	g_pd3dDevice;

	Text::Text(void)
	{
	}

	Text::~Text(void)
	{
	}

	BOOL Text::Init()
	{
		if( FAILED( D3DXCreateFont( 
			g_pd3dDevice, 
			-12, 
			0, 
			FW_BOLD, 
			1, 
			FALSE, 
			DEFAULT_CHARSET,
			OUT_DEFAULT_PRECIS, 
			DEFAULT_QUALITY, 
			DEFAULT_PITCH | FF_DONTCARE,
			"System", &m_pSystemFont ) ) )
		{
			return FALSE;
		}
		if( FAILED( D3DXCreateFont( 
			g_pd3dDevice, 
			-12, 
			0, 
			FW_BOLD, 
			1, 
			FALSE, 
			DEFAULT_CHARSET,
			OUT_DEFAULT_PRECIS, 
			DEFAULT_QUALITY, 
			DEFAULT_PITCH | FF_DONTCARE,
			"System", &m_pDialogFont ) ) )
		{
			return FALSE;
		}
		if( FAILED( D3DXCreateFont( 
			g_pd3dDevice, 
			-12, 
			0, 
			FW_BOLD, 
			1, 
			FALSE, 
			DEFAULT_CHARSET,
			OUT_DEFAULT_PRECIS, 
			DEFAULT_QUALITY, 
			DEFAULT_PITCH | FF_DONTCARE,
			"System", &m_pMaterialsFont ) ) )
		{
			return FALSE;
		}
		return TRUE;
	}

	BOOL Text::DrawText(const char* text ,RECT rc ,TEXT_FORMAT tf)
	{
		switch(tf)
		{
		case SYSTEM_TEXT:
			m_pSystemFont->DrawText( NULL,text, -1, &rc,DT_WORDBREAK, D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f ) );
			break;
		case DIALOG_TEXT:
			m_pDialogFont->DrawText( NULL,text, -1, &rc,DT_WORDBREAK, D3DXCOLOR( 0.0f, 0.0f, 0.0f, 1.0f ) );
			break;
		case MATERIALS_TEXT:
			m_pMaterialsFont->DrawText( NULL,text, -1, &rc,DT_WORDBREAK, D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f ) );
			break;
		default:
			return FALSE;
		}
		return TRUE;
	}
}